package com.jyu.hakkatranslation.controller;


import com.jyu.hakkatranslation.dao.WordEntryMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

/*弃用*/
@Slf4j
@Controller
public class UpLoadController {

    @Autowired
    WordEntryMapper wordEntryMapper;

    // 跳转上传页面
/*
    @RequestMapping("/test")
    public String test() {
        return "test";
    }


    @PostMapping("/upload/music")
    public String upload(@RequestParam("voicefile") MultipartFile[] files,
                         @RequestParam("name")String name,
                         Model model
                         ){
        String filename=null;
        for (MultipartFile file:files) {
            filename = file.getOriginalFilename();
            //动态获取当前项目的路径
            String projectPath = System.getProperty("user.dir");
            //File.separator相当于路径中的/  这能保证在任何系统中都不报错,如果写成/windows下不报错但是在linux下可能会报错
            String destDir = projectPath + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "static" + File.separator + "mp3" + File.separator;

            log.info(filename);
            log.info(destDir);
            // 新建文件
            File filepath = new File(destDir, filename);
            // 判断路径是否存在，如果不存在就创建一个
            if (!filepath.getParentFile().exists()) {
                filepath.getParentFile().mkdirs();
            }
            try {
                // 写入文件
                file.transferTo(new File(destDir + File.separator + filename));
            } catch (IOException e) {
                e.printStackTrace();
            }
            // 将src路径发送至html页面
            model.addAttribute("filename", "/static/mp3/"+filename);

            String mp3_Path = "/mp3/"+filename;

            log.info(mp3_Path);

            wordEntryMapper.save(name,mp3_Path);
        }
        return "test";
    }

*/


}
